﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.CustomRenderTexture
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine.Bindings;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Internal;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>Custom Render Textures are an extension to Render Textures that allow you to render directly to the Texture using a Shader.</para>
  /// </summary>
  [UsedByNativeCode]
  [NativeHeader("Runtime/Graphics/CustomRenderTexture.h")]
  public sealed class CustomRenderTexture : RenderTexture
  {
    [FreeFunction(Name = "CustomRenderTextureScripting::Create")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void Internal_CreateCustomRenderTexture([Writable] CustomRenderTexture rt);

    [NativeName("TriggerUpdate")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void TriggerUpdate(int count);

    /// <summary>
    ///   <para>Triggers an update of the Custom Render Texture.</para>
    /// </summary>
    /// <param name="count">Number of upate pass to perform. The default value of this count parameter is 1.</param>
    public void Update(int count)
    {
      CustomRenderTextureManager.InvokeTriggerUpdate(this, count);
      this.TriggerUpdate(count);
    }

    public void Update() => this.Update(1);

    [NativeName("TriggerInitialization")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void TriggerInitialization();

    /// <summary>
    ///   <para>Initializes the Custom Render Texture at the start of the next frame. Unity calls Initialise() before CustomRenderTexture.Update.</para>
    /// </summary>
    public void Initialize()
    {
      this.TriggerInitialization();
      CustomRenderTextureManager.InvokeTriggerInitialize(this);
    }

    /// <summary>
    ///   <para>Clear all Update Zones.</para>
    /// </summary>
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern void ClearUpdateZones();

    /// <summary>
    ///   <para>The Material that Unity uses to initialize the content of a Custom Render Texture.</para>
    /// </summary>
    public extern Material material { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>The Material that Unity uses to initialize a Custom Render Texture. Initialization texture and color are ignored if you have set this parameter.</para>
    /// </summary>
    public extern Material initializationMaterial { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>The Texture that Unity uses to initialize a Custom Render Texture, multiplied by the initialization color. Unity ignores this parameter if an initializationMaterial is set.</para>
    /// </summary>
    public extern Texture initializationTexture { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    [FreeFunction(Name = "CustomRenderTextureScripting::GetUpdateZonesInternal", HasExplicitThis = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    internal extern void GetUpdateZonesInternal([NotNull("ArgumentNullException")] object updateZones);

    public void GetUpdateZones(List<CustomRenderTextureUpdateZone> updateZones)
    {
      this.GetUpdateZonesInternal((object) updateZones);
    }

    [FreeFunction(Name = "CustomRenderTextureScripting::SetUpdateZonesInternal", HasExplicitThis = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void SetUpdateZonesInternal([Unmarshalled] CustomRenderTextureUpdateZone[] updateZones);

    /// <summary>
    ///   <para>Gets the Render Texture that this Custom Render Texture uses for double buffering.</para>
    /// </summary>
    /// <returns>
    ///   <para>If CustomRenderTexture. doubleBuffered is true, this returns the Render Texture that this Custom Render Texture uses for double buffering. If CustomRenderTexture. doubleBuffered is false, this returns null.</para>
    /// </returns>
    [FreeFunction(Name = "CustomRenderTextureScripting::GetDoubleBufferRenderTexture", HasExplicitThis = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern RenderTexture GetDoubleBufferRenderTexture();

    /// <summary>
    ///   <para>Updates the internal Render Texture that a Custom Render Texture uses for double buffering, so that it matches the size and format of the Custom Render Texture.</para>
    /// </summary>
    [MethodImpl(MethodImplOptions.InternalCall)]
    public extern void EnsureDoubleBufferConsistency();

    /// <summary>
    ///   <para>Setup the list of Update Zones for the Custom Render Texture.</para>
    /// </summary>
    /// <param name="updateZones"></param>
    public void SetUpdateZones(CustomRenderTextureUpdateZone[] updateZones)
    {
      if (updateZones == null)
        throw new ArgumentNullException(nameof (updateZones));
      this.SetUpdateZonesInternal(updateZones);
    }

    /// <summary>
    ///   <para>Determine if Unity initializes the Custom Render Texture with a Texture and a Color or a Material.</para>
    /// </summary>
    public extern CustomRenderTextureInitializationSource initializationSource { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>The color that Unity uses to initialize a Custom Render Texture. Unity ignores this parameter if an initializationMaterial is set.</para>
    /// </summary>
    public Color initializationColor
    {
      get
      {
        Color ret;
        this.get_initializationColor_Injected(out ret);
        return ret;
      }
      set => this.set_initializationColor_Injected(ref value);
    }

    /// <summary>
    ///   <para>Determine how Unity updates the Custom Render Texture.</para>
    /// </summary>
    public extern CustomRenderTextureUpdateMode updateMode { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Determine how Unity initializes a texture.</para>
    /// </summary>
    public extern CustomRenderTextureUpdateMode initializationMode { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>The space in which Unity expresses update zones. You can set this to Normalized or Pixel space.</para>
    /// </summary>
    public extern CustomRenderTextureUpdateZoneSpace updateZoneSpace { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>The Shader Pass Unity uses to update the Custom Render Texture.</para>
    /// </summary>
    public extern int shaderPass { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>The bit field that you can use to enable or disable update on each of the cubemap faces. The bit order from least to most significant bit is as follows: +X, -X, +Y, -Y, +Z, -Z.</para>
    /// </summary>
    public extern uint cubemapFaceMask { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>When this parameter is set to true, Unity double-buffers the Custom Render Texture so that you can access it during its own update.</para>
    /// </summary>
    public extern bool doubleBuffered { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>When this parameter is set to true, Unity wraps Update zones around the border of the Custom Render Texture. Otherwise, Unity clamps Update zones at the border of the Custom Render Texture.</para>
    /// </summary>
    public extern bool wrapUpdateZones { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>The period in seconds that Unity updates real-time Custom Render Textures. A value of 0.0 means Unity updates real-time Custom Render Textures every frame.</para>
    /// </summary>
    public extern float updatePeriod { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Create a new Custom Render Texture.</para>
    /// </summary>
    /// <param name="width"></param>
    /// <param name="height"></param>
    /// <param name="format"></param>
    /// <param name="readWrite"></param>
    public CustomRenderTexture(
      int width,
      int height,
      RenderTextureFormat format,
      [DefaultValue("RenderTextureReadWrite.Default")] RenderTextureReadWrite readWrite)
      : this(width, height, RenderTexture.GetCompatibleFormat(format, readWrite))
    {
    }

    /// <summary>
    ///   <para>Create a new Custom Render Texture.</para>
    /// </summary>
    /// <param name="width"></param>
    /// <param name="height"></param>
    /// <param name="format"></param>
    /// <param name="readWrite"></param>
    [ExcludeFromDocs]
    public CustomRenderTexture(int width, int height, RenderTextureFormat format)
      : this(width, height, format, RenderTextureReadWrite.Default)
    {
    }

    [ExcludeFromDocs]
    public CustomRenderTexture(int width, int height)
      : this(width, height, SystemInfo.GetGraphicsFormat(DefaultFormat.LDR))
    {
    }

    [ExcludeFromDocs]
    public CustomRenderTexture(int width, int height, [DefaultValue("DefaultFormat.LDR")] DefaultFormat defaultFormat)
      : this(width, height, RenderTexture.GetDefaultColorFormat(defaultFormat))
    {
      if (defaultFormat != DefaultFormat.DepthStencil && defaultFormat != DefaultFormat.Shadow)
        return;
      this.depthStencilFormat = SystemInfo.GetGraphicsFormat(defaultFormat);
    }

    [ExcludeFromDocs]
    public CustomRenderTexture(int width, int height, GraphicsFormat format)
    {
      if (format != GraphicsFormat.None && !this.ValidateFormat(format, FormatUsage.Render))
        return;
      CustomRenderTexture.Internal_CreateCustomRenderTexture(this);
      this.width = width;
      this.height = height;
      this.graphicsFormat = format;
      this.SetSRGBReadWrite(GraphicsFormatUtility.IsSRGBFormat(format));
    }

    [SpecialName]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void get_initializationColor_Injected(out Color ret);

    [SpecialName]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void set_initializationColor_Injected(ref Color value);
  }
}
